<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 	<meta charset='UTF-8' />
  <title> jisuanqi</title>
  <style type='text/css'>
	#div{ width:200px; height:300px; border:double; margin:100px auto;}
	#input{ width:196px; height:60px; font-size:33px; text-align:right;}
	.t{ width:43px; height:32px; }
  </style>
	<script type='text/javascript'>
		window.onload = function(){
			var input = document.getElementById('input');
			var table = document.getElementById('table');
			var i = ['平','立','2根','3根','7','8','9','C','4','5','6','*','1','2','3','/','0','-','+','=','.','KJ','',''];
			for(var j=0;j<i.length;j++){
				if(j%4==0){
					var row = table.insertRow(-1);
				}
				var cell = row.insertCell(-1);
				var but = document.createElement('button');
				but.className = 't';
				but.innerHTML = i[j];
				var one,two,operation;
				but.onclick = function(){
					/*if(this.innerHTML=='KJ'){
						this.onclick = function(){*/
							if(input.value == '0'){//去前面的 0
								input.value = null;
							}
							switch(this.innerHTML){
								case '0':
								case '1':
								case '2':
								case '3':
								case '4':
								case '5':
								case '6':
								case '7':
								case '8':
								case '9':
								case '.':
									input.value = input.value+this.innerHTML;
									break;
								case '+':
								case '-':
								case '*':
								case '/':
									one = input.value;//获取第一个值
									input.value = 0;
									operation = this.innerHTML;//获取运算符
									break;
								case '平':
									input.value =input.value * input.value;
									break;
								case '立':
									input.value =input.value * input.value* input.value;
									break;
								case '退':
									
									break;
								case '=':
									two = input.value;//获取第二个值
									input.value = eval(one+operation+two);
									break;
								case 'C':
									input.value = '0';
									one = 0;
									two = 0;
									break;
								default:
									alert('BUG!!!');
							}
						/*}
					}*/
				}
				cell.appendChild(but);
			}
		}	
	</script>
 </head>
 <body>
	<div id='div'>
		<input id='input'   readonly='readonly'/>
		<table id='table' border='1'></table>
	</div>
 </body>
</html>

